﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Admin_PlaneEdit : System.Web.UI.Page
{
    PlaneBusiness pb = new PlaneBusiness();
    private int id = Helper.getQuery("planeID");

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            PlaneEntities pe = pb.getPlane(id);
            if (id > 0)
            {
                btnSubmit.Text = "Sửa";
                txtPlaneName.Text = pe._planeName;
                txtPlaneSymbol.Text = pe._planeSymbol;
                txtPlaneSeat.Text = pe._planeSeat.ToString();
                txtPlaneInfo.Text = pe._planeInfo;
            }
            else
                btnSubmit.Text = "Thêm mới";
        }
    }
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        PlaneEntities pe = new PlaneEntities();
        pe._planeID = id;
        pe._planeSymbol = txtPlaneSymbol.Text;
        pe._planeName = txtPlaneName.Text;
        pe._planeSeat = int.Parse(txtPlaneSeat.Text);
        pe._planeInfo = txtPlaneInfo.Text;
        if (btnSubmit.Text == "Thêm mới")
        {

            if (pb.Insert(pe))
                Response.Redirect("Plane.aspx");
            else
                Label1.Text = "Chưa thêm được";
        }
        else
        {
            if (pb.Edit(pe))
                Response.Redirect("Plane.aspx");
            else
                Label1.Text = "Chưa sửa được";
        }
    }
}